package com.grom.dao;

import java.util.List;

import com.grom.po.StoreInfo;
import com.grom.util.IDCreator;
import com.holder.DBContextHolder;
import com.holder.DBUTil;

class StoreInfoDaoImpl implements StoreInfoDao {

	public List<StoreInfo> getAllStoreInfo() {
		DBContextHolder.setContextConnection(DatabaseDao.getConnection());
		return DBUTil.select(StoreInfo.class);
	}

	public void add(StoreInfo storeInfo) {
		storeInfo.setID(IDCreator.getSingleId());
		DBContextHolder.setContextConnection(DatabaseDao.getConnection());
		DBUTil.save(storeInfo);
	}

	public void update(StoreInfo storeInfo) {
		DBContextHolder.setContextConnection(DatabaseDao.getConnection());
		DBUTil.update(storeInfo);
	}

	@Override
	public StoreInfo getStoreInfoById(String id) {
		String sql = "select * from storeinfo where id ='" + id + "'";
		DBContextHolder.setContextConnection(DatabaseDao.getConnection());
		List<StoreInfo> resutl = DBUTil.getResult(sql, StoreInfo.class);
		return resutl.get(0);
	}

	@Override
	public void delete(StoreInfo storeInfo) {
		DBContextHolder.setContextConnection(DatabaseDao.getConnection());
		DBUTil.delete(storeInfo);
	}

	@Override
	public List<StoreInfo> conditionSelect(String sql) {
		DBContextHolder.setContextConnection(DatabaseDao.getConnection());
		List<StoreInfo> result = DBUTil.getResult(sql, StoreInfo.class);
		return result;
	}

}
